<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>mknod</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade>
<h4><a name = "tag_000_007_642">&nbsp;</a>NAME</h4><blockquote>
mknod - make a directory, a special or regular file
</blockquote><h4><a name = "tag_000_007_643">&nbsp;</a>SYNOPSIS</h4><blockquote>
<pre><code>

#include &lt;<a href="sysstat.h.html">sys/stat.h</a>&gt;

int mknod(const char *<i>path</i>, mode_t <i>mode</i>, dev_t <i>dev</i>);
</code>
</pre>
</blockquote><h4><a name = "tag_000_007_644">&nbsp;</a>DESCRIPTION</h4><blockquote>
The
<i>mknod()</i>
function creates a new file named by the pathname to which the argument
<i>path</i> points.
<p>
The file type for <i>path</i> is OR-ed into the <i>mode</i> argument, and
must be selected from one of the following symbolic constants:
<p><table  bordercolor=#000000 border=1 align=center><tr valign=top><th align=center><b>Name</b>
<th align=center><b>Description</b>
<tr valign=top><td align=left>S_IFIFO
<td align=left>FIFO-special
<tr valign=top><td align=left>S_IFCHR
<td align=left>Character-special (non-portable)
<tr valign=top><td align=left>S_IFDIR
<td align=left>Directory (non-portable)
<tr valign=top><td align=left>S_IFBLK
<td align=left>Block-special (non-portable)
<tr valign=top><td align=left>S_IFREG
<td align=left>Regular (non-portable)
</table>
<p>
The only portable use of
<i>mknod()</i>
is to create a FIFO-special file.
If
<i>mode</i>
is not S_IFIFO or
<i>dev</i>
is not 0, the behaviour of
<i>mknod()</i>
is unspecified.
<p>
The permissions for the new file are OR-ed into the <i>mode</i> argument, and
may be selected from any combination of the following symbolic constants:
<p><table  bordercolor=#000000 border=1 align=center><tr valign=top><th align=center><b>Name</b>
<th align=center><b>Description</b>
<tr valign=top><td align=left>S_ISUID
<td align=left>Set user ID on execution.
<tr valign=top><td align=left>S_ISGID
<td align=left>Set group ID on execution.
<tr valign=top><td align=left>S_IRWXU
<td align=left>Read, write or execute (search) by owner.
<tr valign=top><td align=left>S_IRUSR
<td align=left>Read by owner.
<tr valign=top><td align=left>S_IWUSR
<td align=left>Write by owner.
<tr valign=top><td align=left>S_IXUSR
<td align=left>Execute (search) by owner.
<tr valign=top><td align=left>S_IRWXG
<td align=left>Read, write or execute (search) by group.
<tr valign=top><td align=left>S_IRGRP
<td align=left>Read by group.
<tr valign=top><td align=left>S_IWGRP
<td align=left>Write by group.
<tr valign=top><td align=left>S_IXGRP
<td align=left>Execute (search) by group.
<tr valign=top><td align=left>S_IRWXO
<td align=left>Read, write or execute (search) by others.
<tr valign=top><td align=left>S_IROTH
<td align=left>Read by others.
<tr valign=top><td align=left>S_IWOTH
<td align=left>Write by others.
<tr valign=top><td align=left>S_IXOTH
<td align=left>Execute (search) by others.
<tr valign=top><td align=left>S_ISVTX
<td align=left>On directories, restricted deletion flag.
</table>
<p>
The user ID of the file is initialised to the effective user ID of the
process.  The group ID of the file is initialised to either the effective
group ID of the process or the group ID of the parent directory.
<p>
The owner, group, and other permission bits of <i>mode</i> are modified by the
file mode creation mask of the process.  The
<i>mknod()</i>
function
clears each bit whose corresponding bit in the file mode
creation mask of the process is set.
<p>
Upon successful completion,
<i>mknod()</i>
marks for update the
<i>st_atime</i>,
<i>st_ctime</i>
and
<i>st_mtime</i>
fields of the file.  Also, the
<i>st_ctime</i>
and
<i>st_mtime</i>
fields of the directory that contains the new entry are marked for update.
<p>
Only a process with appropriate privileges may invoke
<i>mknod()</i>
for file types other than FIFO-special.
</blockquote><h4><a name = "tag_000_007_645">&nbsp;</a>RETURN VALUE</h4><blockquote>
Upon successful completion,
<i>mknod()</i>
returns 0.  Otherwise, it returns -1, the new file is
not created, and <i>errno</i> is set to indicate the error.
</blockquote><h4><a name = "tag_000_007_646">&nbsp;</a>ERRORS</h4><blockquote>
The
<i>mknod()</i>
function will fail if:
<dl compact>

<dt>[EPERM]<dd>
The invoking process does not have appropriate privileges and the
file type is not FIFO-special.

<dt>[ENOTDIR]<dd>
A component of the path prefix is not a directory.

<dt>[ENOENT]<dd>
A component of the path prefix specified by <i>path</i> does not name an
existing directory or <i>path</i> is an empty string.

<dt>[EACCES]<dd>
A component of the path prefix denies search permission, or write permission
is denied on the parent directory.

<dt>[EROFS]<dd>
The directory in which the file is to be created is located on a read-only
file system.

<dt>[EEXIST]<dd>
The named file exists.

<dt>[EIO]<dd>
An I/O error occurred while accessing the file system.

<dt>[EINVAL]<dd>
An invalid argument exists.

<dt>[ENOSPC]<dd>
The directory that would contain the new file cannot be extended or
the file system is out of file allocation resources.

<dt>[ELOOP]<dd>
Too many symbolic links were encountered in resolving <i>path</i>.

<dt>[ENAMETOOLONG]<dd>

The length of a pathname exceeds {PATH_MAX}, or pathname
component is longer than {NAME_MAX}.

</dl>
<p>
The
<i>mknod()</i>
function may fail if:
<dl compact>

<dt>[ENAMETOOLONG]<dd>

Pathname resolution of a symbolic link produced an intermediate result whose
length exceeds {PATH_MAX}.

</dl>
</blockquote><h4><a name = "tag_000_007_647">&nbsp;</a>EXAMPLES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_007_648">&nbsp;</a>APPLICATION USAGE</h4><blockquote>
For portability to implementations conforming to earlier versions of this
specification,
<i><a href="mkfifo.html">mkfifo()</a></i>
is preferred over this function for making FIFO special files.
</blockquote><h4><a name = "tag_000_007_649">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_007_650">&nbsp;</a>SEE ALSO</h4><blockquote>
<i><a href="chmod.html">chmod()</a></i>,
<i><a href="creat.html">creat()</a></i>,
<i><a href="exec.html">exec</a></i>,
<i><a href="mkdir.html">mkdir()</a></i>,
<i><a href="mkfifo.html">mkfifo()</a></i>,
<i><a href="open.html">open()</a></i>,
<i><a href="stat.html">stat()</a></i>,
<i><a href="umask.html">umask()</a></i>,
<i><a href="sysstat.h.html">&lt;sys/stat.h&gt;</a></i>.
</blockquote><hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>
